﻿using System.Data;
using System.Data.SqlClient;

/// <summary>
/// 操作日志
/// </summary>
public class OperateLog
{
    /// <summary>
    /// 添加操作成功日志
    /// </summary>
    /// <param name="userId">用户id</param>
    /// <param name="ip">ip</param>
    /// <param name="description">描述</param>
    public static void AddSuccessLog(int userId, string ip, string description)
    {
        AddLog(userId, ip, 1, description);
    }

    /// <summary>
    /// 添加操作失败日志
    /// </summary>
    /// <param name="userId">用户id</param>
    /// <param name="ip">ip</param>
    /// <param name="description">描述</param>
    public static void AddFailedLog(int userId, string ip, string description)
    {
        AddLog(userId, ip, 0, description);
    }

    /// <summary>
    /// 添加操作日志
    /// </summary>
    /// <param name="userId">用户id</param>
    /// <param name="ip">ip</param>
    /// <param name="state">状态</param>
    /// <param name="description">描述</param>
    public static void AddLog(int userId, string ip, byte state, string description)
    {
        string sql = "INSERT INTO [lt_operatelog]([o_userid], [o_ip], [o_state], [o_description]) VALUES(@o_userid, @o_ip,@o_state,@o_description)";
        SqlParameter[] parameters = new SqlParameter[]{
            SqlParameterEx.CreateParameter("@o_userid", SqlDbType.Int, userId),
            SqlParameterEx.CreateParameter("@o_ip", SqlDbType.VarChar, 50, ip),
            SqlParameterEx.CreateParameter("@o_state", SqlDbType.TinyInt, state),
            SqlParameterEx.CreateParameter("@o_description", SqlDbType.VarChar, 200, description)
        };
        SqlHelper.Instance.ExecuteNonQuery(sql, parameters);
    }
}